<?php
namespace app\setup\controller;
use think\Controller;
use think\Db;
use think\Session;
use think\Request;

class Information extends Controller
{
    public function index()
    {
        //查询
        $id = Session::get('id');
        $list = Db::table('user_data')->where('uid',$id)->find();
        $list_info = Db::table('user_info')->where('uid',$id)->find();

        var_dump($id);
        var_dump($list);
        $this->assign('list_info',$list_info);
        $this->assign('emotion',$list['emotion']);
        $this->assign('signature_gx',$list['signature_gx']);
        $this->assign('signature_gr',$list['signature_gr']);
        $list['blood'] == 'A' ? $selected1 = 'selected' : $selected1 = '' ;
        $list['blood'] == 'B' ? $selected2 = 'selected' : $selected2 = '' ;
        $list['blood'] == 'AB' ? $selected3 = 'selected' : $selected3 = '' ;
        $list['blood'] == 'O' ? $selected4 = 'selected' : $selected4 = '' ;
        $list['blood'] == 'X' ? $selected5 = 'selected' : $selected5 = '' ;
        $this->assign('blood',$list['blood']);
        
        $this->assign('selected1',$selected1);
        $this->assign('selected2',$selected2);
        $this->assign('selected3',$selected3);
        $this->assign('selected4',$selected4);
        $this->assign('selected5',$selected5);

        return $this->fetch('index/information');
    }

    //更新数据
    public function update()
    {
        if(request()->isPost()){
            //获取提交的数据
        $data = Request::instance()->post();
        $id = Session::get('id');
        var_dump($data);
        }
        
        $result = Db::table('user_data')->where('uid',$id)->update(['emotion'=>$data['emotion'],'blood'=>$data['blood'],'signature_gx'=>$data['signature_gx'],'signature_gr'=>$data['signature_gr']]);
        var_dump($result);
        return $this->redirect('information/index');
    }
}
